/**
 * 版权所有:版权所有(C) 2020，卓信科技
 * 系统名称:FOL2020-财务在线
 * 文件名称:GlobalVal.java
 * 模块名称:全局变量
 * 创建日期:2020年5月11日
 * 作        者:Baisong
 * 内容摘要:全局变量
 */
package com.zx.sframe.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import com.zx.platform.syscontext.PlatformGlobalVar;

/**
 * 类  名  称:GlobalVal
 * 内容摘要:TODO(这里详细描述这个类的作用)
 * 作        者:Baisong
 */
@Component
public class GlobalVal
{
    private static Logger log = LoggerFactory.getLogger(GlobalVal.class);

    public static ApplicationContext ctx;

    public static final String USER_SESSION = "userSession";

    public static final String ALL_DEFAULT_VAL = "0";

    public static final String ADMIN_NAME = PlatformGlobalVar.SYS_PROPERTIES.get("adminName");

    public static final String ADMIN_PASS_WD = PlatformGlobalVar.SYS_PROPERTIES.get("adminPassWd");

    // 是否需要在接口平台登录
    public static final String IS_P_LOGIN = PlatformGlobalVar.SYS_PROPERTIES.get("is_p_login");

    public static final String EKP_LOGIN_URL = PlatformGlobalVar.SYS_PROPERTIES.get("ekp_login_url");

    public static final String SERVER_WMS_URL = PlatformGlobalVar.SYS_PROPERTIES.get("server_wms_url");

    public static final String SERVER_UP_URL = PlatformGlobalVar.SYS_PROPERTIES.get("server.ifcFileUrl");

    public static final String SERVER_UPLOAD_URL = PlatformGlobalVar.SYS_PROPERTIES.get("server_upload_url");

    public static final String SERVER_COMPRESS_URL = PlatformGlobalVar.SYS_PROPERTIES.get("server_compress_url");

    public static final String SERVER_UPLOAD_LOCAL_URL = PlatformGlobalVar.SYS_PROPERTIES.get("server_upload_local_url");

    public static final String SYNDB_NAME = PlatformGlobalVar.SYS_PROPERTIES.get("syndb_name");

    // 是否为测试环境
    public static final String IS_TEST = PlatformGlobalVar.SYS_PROPERTIES.get("is_test");

    // 是否发送微信消息
    public static final String IS_SEND_VX_MSG = PlatformGlobalVar.SYS_PROPERTIES.get("is_send_vx_msg");

    // 是否发送微信消息
    public static final String IS_SEND_EMAIL_MSG = PlatformGlobalVar.SYS_PROPERTIES.get("is_send_email_msg");

    // 用户登录后接口平台返回的用户信息
    public static final String PERSONNEL_ENCRYPTIONID = "encryptionId";

    /**
     * 最高级菜单的定义
     */
    public final static String UNIT_LEVEL = "1";

    public final static String P_DEPT_ID = "0";

	public static void init() 
	{
        try
        {
            ctx = PlatformGlobalVar.APPLICATION_CONTEXT;
        }
        catch (Exception e)
        {

            log.error("==Application init ERROR!!==" + e.getMessage());
            e.printStackTrace();
        }
	}
	
	public static ApplicationContext getApplicationContext() 
	{
		return ctx;
	}
	
	/**
	 * setApplicationContext
	 **/
	public static void setApplicationContext(ApplicationContext applicationContextParam) throws BeansException
	{
		ctx = applicationContextParam;
	}

	/**
	 * getObject
	 **/
	public static Object getObject(String id)
	{
		Object object = null;
		object = ctx.getBean(id);
		return object;
	}

	/**
	 * getObject
	 **/
	public static <T> T getObject(Class<T> tClass)
	{
		return ctx.getBean(tClass);
	}

	/**
	 * getBean
	 **/
	public static Object getBean(String tClass)
	{
		return ctx.getBean(tClass);
	}

	/**
	 * getBean
	 **/
	public <T> T getBean(Class<T> tClass)
	{
		return getApplicationContext().getBean(tClass);
	}
	
	
	
}
